// 历史处方
import React, { useEffect, useState } from 'react'
import { useNavigate, useSearchParams } from 'react-router-dom'
import { Button, Space,Toast  } from 'antd-mobile'
import axios from 'axios'
export default function Hist() {
  let navigate = useNavigate()
  let [search] = useSearchParams()
  let [item, setItem] = useState({})
  let [y, setY] = useState([])
  let id = search.get('id')
  // console.log(id);

  let top = () => {
    navigate(-1)
  }
  useEffect(() => {
    getinfo()
    gety()
  }, [])
  let getinfo = async () => {
    // console.log(id);

    let { data: { data } } = await axios.get('http://127.0.0.1:3000/mxd_infoid', { params: { id } })
    console.log(data);
    setItem(data)
  }
  let gety = async () => {
    let { data: { data } } = await axios.get('http://127.0.0.1:3000/mxd_getids', { params: { id } })
    // console.log(data);
    setY(data)

  }
  const upcf=async(item)=>{
    console.log(item);
    item.zt=!item.zt
    // let info=bar2.find(item=>item._id==id)
    // console.log(info);
    
    // info.zt=!info.zt
    // console.log(info,'222');
    let {data}=await axios.post('http://127.0.0.1:3000/mxd_cf',item)

    console.log(data);
    navigate('/gg/ks')
    // getbar2()
    // Toast.show({
    //   icon:'success',
    //   content:'设置成功'
    // })
    
      
  }
  return (
    <div id='histcf'>
      <div className="top">
        <p>
          <span>
            <svg onClick={top} style={{ width: '30px', height: '35px', position: 'absolute', marginLeft: '5px' }} t="1724675809513" className="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2590" width="200" height="200"><path d="M670.6 861.6c-7.6 0-15.1-2.9-20.9-8.6L329.4 532.7c-11.6-11.5-11.6-30.3 0-41.8l320.2-320.2c5.8-5.8 13.3-8.6 20.9-8.6 7.5 0 15.1 2.9 20.9 8.6 11.5 11.5 11.5 30.2 0 41.8L392 511.8l299.4 299.4c11.5 11.6 11.5 30.3 0 41.8-5.7 5.7-13.3 8.6-20.8 8.6z" fill="#2c2c2c" p-id="2591"></path></svg>
          </span>
          <span style={{ marginLeft: '35px', marginTop: '10px', lineHeight: '33px', fontSize: '20px' }}>历史处方详情</span>

        </p>
        <hr />
      </div>

      <div className="big">
        <p>患者姓名：{item.ptname}</p>
        <p>年龄：{item.ptage}</p>
        <p>性别：{item.ptsex?'男':'女'}</p>
      </div>
      <div className="big2">
        <p>初步诊断：{item.zd}</p>
        <p>处理意见：{item.yj}</p>
      </div>
      <div className="big3">
        <span >Rp</span>
        {y.map(item => (
          <div key={item._id} className="small">

            <br />
            <p>【代文】{item.name}</p>
            <p style={{whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>规格：{item.grade}</p>
            <p style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{item.usage}</p>
          </div>
        ))}


      </div>
      <div className="big4">
        <p>处方医师：{item.dname}</p>
        <p>科室：{item.ks}</p>
      </div>
      <div className="big5">
        <Button onClick={()=>{upcf(item)}} style={{marginLeft:'50px',marginTop:'10px'}} shape='rounded' color='primary' fill='outline'>
          设置为常用处方
        </Button>
        <Button onClick={()=>{navigate('/gg/continue?id='+item._id)}} style={{marginLeft:'50px',marginTop:'10px'}} shape='rounded' color='primary' fill='solid'>
          续处方
        </Button>
      </div>

    </div>
  )
}
